<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use DateTimeInterface;

/**
 * 退货商品
 * Class SalesReturnGoodsDetailModel
 * @package App\Models
 */
class SalesReturnGoodsDetailModel extends Model
{
    protected $table = 'sales_return_goods_detail';

    protected $dateFormat = 'U';//这个时间字段被为被格式化为UNIX 时间戳的形式存储
    //toArray 时间转换问题
    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }

    static public function getGoodsDetailInfo($salesId, $condition)
    {
        return SELF::select(
            'return_id'
        )
            ->from('sales_return_goods_detail as a')
            ->leftJoin('materiel_type as b', 'a.materiel_type_id', '=', 'b.id')
            ->where($condition)
            ->whereIn('return_id', $salesId)
            ->distinct()
            ->get()->toArray();
    }
}
